package net.sumcraft.pointconvert;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitScheduler;

/**
 * Created by zhen on 2017/7/1.
 */
public class MyCommand implements CommandExecutor {
    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
        if (sender instanceof Player) {
            String url = PointConvert.cfg.getString("web.apiurl");
            String servercode = PointConvert.cfg.getString("web.servercode");
            String serverid = PointConvert.cfg.getString("web.serverid");
            Player player = (Player) sender;
            if (cmd.getName().equalsIgnoreCase("zh")) {
                String str = "serverid=" + serverid + "&username=" + player.getName() + "&servercode=" + servercode;
                //Thread t = new Thread(new ConvertPointsRunnable(player, str, url));
                Bukkit.getScheduler().runTaskAsynchronously(PointConvert.pointConvert,new ConvertPointsRunnable(player, str, url));
                player.sendMessage(ChatColor.GREEN + "开始转换晶石.....");
                return true;
            }

        } else return false;
        return false;
    }
}
